Skip to content

scripts: harden rmg_kinetics & rmg_thermo#889

Open
alongd wants to merge 1 commit into
mainfrom
rmg_kinetics
Open

scripts: harden rmg_kinetics & rmg_thermo#889
alongd wants to merge 1 commit into
mainfrom
rmg_kinetics

Conversation

@alongd
Copy link
Copy Markdown
Member

@alongd alongd commented May 14, 2026

Deep-copy DB kinetics before scaling so a second query can't read a doubly-scaled A, gate change_rate on Arrhenius/EP so non-Arrhenius forms (Chebyshev/PLOG/etc.) are skipped safely, add sys.path bootstrap so from common import ... works regardless of CWD, add an --output flag so the input YAML isn't overwritten, document the training-entry filter and output units, and harden the helper's debug print against reactions without reactants. Adds argparse + subprocess unit tests.

Fixes from CC review: deep-copy DB kinetics before scaling so a second
query can't read a doubly-scaled A, gate change_rate on Arrhenius/EP so
non-Arrhenius forms (Chebyshev/PLOG/etc.) are skipped safely, add
sys.path bootstrap so `from common import ...` works regardless of CWD,
add an --output flag so the input YAML isn't overwritten, document the
training-entry filter and output units, and harden the helper's debug
print against reactions without reactants. Adds argparse + subprocess
unit tests.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@alongd alongd requested a review from Copilot May 14, 2026 16:10
@alongd alongd changed the title scripts: harden rmg_kinetics & rmg_thermo against review feedback scripts: harden rmg_kinetics & rmg_thermo May 14, 2026
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR hardens ARC’s standalone RMG helper scripts (thermo + kinetics) based on prior review feedback, improving correctness across repeated database queries, safer handling of unsupported kinetics forms, and more robust CLI invocation/testing.

Changes:

  • Added --output/-o support (and preserved default overwrite behavior) so scripts can write results to a separate YAML file.
  • Hardened rmg_kinetics.py by deep-copying database kinetics before in-place mutation and guarding change_rate() to Arrhenius-like kinetics.
  • Improved script portability by bootstrapping sys.path so from common import ... works regardless of current working directory; added/expanded unit tests.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
arc/scripts/rmg_thermo.py Adds sys.path bootstrap and supports writing results to an optional output YAML path.
arc/scripts/rmg_kinetics.py Deep-copies kinetics before mutation, guards degeneracy scaling, improves debug printing, adds --output, and updates documentation.
arc/scripts/common.py Extends the shared argparse parser with an optional --output/-o flag.
arc/scripts_test.py Adds unit tests for argparse, helper behavior, and --output non-overwrite behavior via conda run.
Comments suppressed due to low confidence (1)

arc/scripts/rmg_kinetics.py:117

  • A_units is only set for bimolecular vs 'everything else'. For termolecular reactions (len(reactants)==3), this will incorrectly treat A as s^-1 and skip the needed m^6→cm^6 scaling, even though loop_families supports 3 reactants/products. Consider adding an explicit 3-reactant branch (and corresponding scaling) or rejecting/flagging unsupported reaction orders.
    # Families:
    A_units = "cm^3/(mol*s)" if len(reaction.reactants) == 2 else "s^-1"
    fam_list = loop_families(rmgdb, reaction)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +8 to +10
- ``A``: cm^3/(mol*s) for bimolecular reactions, s^-1 for unimolecular
(3-body: cm^6/(mol^2*s)). Reported in the units stored on the
Arrhenius object after the SI->cm conversion below.
Comment thread arc/scripts_test.py
Unit tests for ``rmg_kinetics.py`` helpers that don't need a full RMG database load.

Each test runs a tiny ``python -c`` snippet inside ``rmg_env`` so we can import
rmgpy and the script module directly. Stdout is parsed as YAML.
Comment thread arc/scripts_test.py
Comment on lines +207 to +226
"""The new isinstance gate must skip ``change_rate`` for non-Arrhenius kinetics
(e.g. Chebyshev) rather than blindly mutating them."""
snippet = textwrap.dedent(f"""
import sys
sys.path.insert(0, {self.SCRIPT_DIR!r})
from rmgpy.kinetics import Arrhenius, ArrheniusEP
# Sanity: the script imports the same classes we test against.
import rmg_kinetics as rk
assert rk.Arrhenius is Arrhenius
assert rk.ArrheniusEP is ArrheniusEP
# The guard logic itself is a one-line isinstance check; replicate it here
# so a regression that drops the guard would fail the test.
from rmgpy.kinetics import Chebyshev
cheb = Chebyshev(coeffs=[[1.0, 0.0], [0.0, 0.0]],
kunits='cm^3/(mol*s)',
Tmin=(300.0, 'K'), Tmax=(2000.0, 'K'),
Pmin=(0.01, 'bar'), Pmax=(100.0, 'bar'))
assert not isinstance(cheb, (rk.Arrhenius, rk.ArrheniusEP))
arr = Arrhenius(A=(1.0, 's^-1'), n=0.0, Ea=(0.0, 'J/mol'))
assert isinstance(arr, (rk.Arrhenius, rk.ArrheniusEP))
Comment thread arc/scripts_test.py
)
self.assertEqual(result.returncode, 0, f'thermo script failed: {result.stderr}')

# Input must be byte-identical (no overwrite).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants